Skip to content

polite handling of nan in irradiance.perez - #610

Closed
cwhanse wants to merge 2 commits into
pvlib:masterfrom
cwhanse:perez_nan
Closed

cwhanse wants to merge 2 commits into
pvlib:masterfrom
cwhanse:perez_nan

Conversation

@cwhanse

@cwhanse cwhanse commented Oct 23, 2018

Copy link
Copy Markdown
Member

pvlib python pull request guidelines

Thank you for your contribution to pvlib python! You may delete all of these instructions except for the list below.

You may submit a pull request with your code at any stage of completion.

The following items must be addressed before the code can be merged. Please don't hesitate to ask for help if you're unsure of how to accomplish any of the items below:

  • [x ] I am familiar with the contributing guidelines.
  • [x ] Fully tested. Added and/or modified tests to ensure correct behavior for all reasonable inputs. Tests (usually) must pass on the TravisCI and Appveyor testing services.
  • Adds description and name entries in the appropriate docs/sphinx/source/whatsnew file for all changes.
  • Code quality and style is sufficient. Passes LGTM and SticklerCI checks.
  • New code is fully documented. Includes sphinx/numpydoc compliant docstrings and comments in the code where necessary.
  • Pull request is nearly complete and ready for detailed review.

Brief description of the problem and proposed solution (if not already fully described in the issue linked to above):

Comment thread pvlib/irradiance.py Outdated

F2 = (F2c[ebin, 0] + F2c[ebin, 1] * delta + F2c[ebin, 2] * z)
F2 = np.maximum(F2, 0)
F2 = np.where(np.isnan(F2), np.nan, np.maximum(F2, 0))

@mikofski mikofski Oct 23, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this polite handling is going to become a pattern, it might be worth putting it into tools as a dedicated set of functions like

def polite_handling_of_nan(x, f):
    """return nan where x is nan otherwise return f(x)"""
    return np.where(np.isnan(x), np.nan, f(x))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also isn't another option to turn off NumPy warnings? If that's an alternate, I'm curious if there is any penalty for calling np.where() all the time, instead of just ignoring the warnings.

@cwhanse

cwhanse commented Oct 23, 2018

Copy link
Copy Markdown
Member Author

Actually that earlier commit did nothing, since np.where evaluates both cases before constructing its output. See the latest commit, adding nanmaximum to pvlib.tools.

Having np.nan in series inputs like dni and airmass should be handled gracefully, where we can.

@wholmgren

Copy link
Copy Markdown
Member

np.fmax documentation says "See Also... maximum Element-wise maximum of two arrays, propagates NaNs."

It is ridiculous that a function specifically advertised to propagate NaNs would also complain that it was provided a NaN! There's got to be a better way than trying to maintain our own nan-friendly maximum function.

@cwhanse

cwhanse commented Oct 24, 2018

Copy link
Copy Markdown
Member Author

I agree. We could open an issue for numpy...

@wholmgren

Copy link
Copy Markdown
Member

I'm working on a comment here.... numpy/numpy#12038

@cwhanse

cwhanse commented Oct 24, 2018

Copy link
Copy Markdown
Member Author

OK, let's sit on this until numpy makes up its mind. The custom function is messing with the output typing in irradiance.perez

@mikofski

Copy link
Copy Markdown
Member

Also I'm still concerned about penalty from all these extra np.where calls if we can just turn this warning off as I asked in this comment

@wholmgren

Copy link
Copy Markdown
Member

Looks like numpy will stop emitting the warnings. I suggest we live with them for now and close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants